


package yf.mall.controller;
import com.yf.request.SearchParam;
import java.io.IOException;
import java.util.List;
import com.yf.response.RRException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import yf.mall.vo.LevelRecordVo;
import yf.mall.service.LevelRecordService;
import com.yf.response.R;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import org.springframework.web.multipart.MultipartFile;
                                        

@RestController
@RequestMapping("/level/record")
public class LevelRecordController {
    @Autowired
    private LevelRecordService levelRecordService;

    /**
     * 列表级别记录
     */
    @SysLog("查看级别记录")
    @RequestMapping("/list")
    @RequiresPermissions("level:record:list")
    public R list(@RequestBody SearchParam<LevelRecordVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<LevelRecordVo> list = levelRecordService.findVo(params.getEntity());
        return R.ok(new PageInfo(list));
    }

    /**
 * 下载
 */
    @SysLog("下载")
    @RequestMapping("/down")
    @RequiresPermissions("level:record:list")
    public void down(@RequestBody SearchParam<LevelRecordVo> params, HttpServletResponse response) {
        List<LevelRecordVo> list = levelRecordService.findVo(params.getEntity());
            levelRecordService.downLoad(response, list);
    }

    /**
 * 上传
 *
 * @param file
 */
    @RequestMapping("/upload")
    public void upload(MultipartFile file) {
        try {
                levelRecordService.upload(file.getInputStream());
        } catch (IOException e) {
            throw new RRException("上传的文件有误!");
        }
    }


    /**
     * 查看级别记录
     */
    @SysLog("查看级别记录")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("level:record:info")
    public R info(@PathVariable("id") Long id) {
            LevelRecordVo vo = levelRecordService.getVo(id);

        return R.ok(vo);
    }

    /**
     * 保存级别记录
     */
    @SysLog("保存级别记录")
    @RequestMapping("/save")
    @RequiresPermissions("level:record:save")
    public R save(@RequestBody LevelRecordVo vo) {
            levelRecordService.saveVo(vo);
        return R.ok(vo);
    }

    /**
     * 修改级别记录
     */
    @SysLog("修改级别记录")
    @RequestMapping("/update")
    @RequiresPermissions("level:record:update")
    public R update(@RequestBody LevelRecordVo vo) {
            levelRecordService.updateVo(vo);

        return R.ok(vo);
    }

    /**
     * 删除级别记录
     */
    @SysLog("删除级别记录")
    @RequestMapping("/delete")
    @RequiresPermissions("level:record:delete")
    public R delete(Long[]ids) {
            levelRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有级别记录
     */
    @SysLog("所有级别记录")
    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order!=null ? order : "id desc");
        List<LevelRecordVo> list = levelRecordService.findVo(null);
        return R.ok(list);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
                                                                                                                                                                                                                        return R.ok(options);
    }





    /***********自定义开始***********/
}
